{template 'common/header'}
<style>
.table td span{display:inline-block;margin-top:4px;}
.table td input{margin-bottom:0;}
</style>
	{if $rid!=''}
		{template 'nav'}
	{/if}
{if $operation == 'display'}

<div class="panel panel-default">
	<div class="table-responsive panel-body">
		<table class="table">
			<thead>
				<tr>
					<th style="width:50px">排序</th>
					<th>标题</th>
					<th style="width:50px;">点击</th>
					<th style="width:200px; text-align:right;">操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $item}
				<tr>
					<td>{if !empty($item['pcate'])}<span>{$item['displayorder']}</span>{else}{$item['displayorder']}{/if}</td>
					<td>
						
						<a href="javascript::;" style="color:#333;">{$item['title']}</a>
					</td>
					
					<td>
						<span class="label label-success">{$item['click']}</span>
					</td>
					<td style="text-align:right;">
						<a href="javascript:;" onclick="preview_article('{$item['id']}', '{$_W['uniacid']}');return false;" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="预览"><i class="fa fa-search"></i> </a>
						<a href="javascript:void(0)" id="{$item['id']}" class="btn btn-default btn-sm manage" data-toggle="tooltip" data-placement="top" title="群发文章"><i class="fa fa-gift"></i> 群发</a>
						<a href="{php echo $this->createWebUrl('fmqf', array('op' => 'post','rid' => $rid,'id' => $item['id']))}" title="编辑" data-toggle="tooltip" data-placement="top" class="btn btn-default btn-sm"><i class="fa fa-edit"></i></a>
						<a onclick="return confirm('此操作不可恢复，确认吗？'); return false;" href="{php echo url('site/article/delete', array('id' => $item['id']))}" title="删除" data-toggle="tooltip" data-placement="top" class="btn btn-default btn-sm"><i class="fa fa-times"></i></a>
					</td>
				</tr>
				{/loop}
			</tbody>
		</table>
	</div>
</div>
{$pager}
<script type="text/javascript">
	var category = {php echo json_encode($children)};
	require(['bootstrap'],function($){
		$('.btn').hover(function(){
			$(this).tooltip('show');
		},function(){
			$(this).tooltip('hide');
		});
	});
	require(['jquery', 'util'], function($, u){
		$('.manage').click(function(){
			var id = parseInt($(this).attr('id'));
			$.get("{php echo $this->createWebUrl('fmqf', array('op' => 'fasong','rid' => $rid))}&id=" + id, function(data){
				if(data == 'dataerr') {
					u.message('未找指定文章', '', 'error');
				} else {
					var obj = u.dialog('群发消息', data, $('#guanbi').html());
				}
				obj.modal('show');
			});
		})	
	});	
	function preview_article(id, uniacid) {
		require(['jquery', 'util'], function($, u){
			var content = '<iframe width="320" scrolling="yes" height="480" frameborder="0" src="about:blank"></iframe>';
			var footer = '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>';
			var dialog = u.dialog('预览文章', content, footer);
			dialog.find('iframe').on('load', function(){
				$('a', this.contentWindow.document.body).each(function(){
					var href = $(this).attr('href');
					if(href && href[0] != '#') {
						var arr = href.split(/#/g);
						var url = arr[0];
						if (url.substr(0, 3) == 'www') {
							url = 'http://' + url;
						}
						if(arr[1]) {
							url += ('#' + arr[1]);
						}
						if (url.substr(0, 10) == 'javascript') {
							url = url.substr(0, url.lastIndexOf('&'));
						}
						$(this).attr('href', url);
					}
				});
			});
			var url = '../app/index.php?c=site&a=site&do=detail&id=' + id + '&i=' + uniacid;
			dialog.find('iframe').attr('src', url);
			dialog.find('.modal-dialog').css({'width': '322px'});
			dialog.find('.modal-body').css({'padding': '0', 'height': '480px'});
			dialog.modal('show');
		});
	}
</script>
{elseif $operation == 'post'}
<div class="clearfix">
<form class="form-horizontal form" action="" method="post" enctype="multipart/form-data">
	<div class="panel panel-default">
		<div class="panel-heading">群发文章管理</div>
		<div class="panel-body">
				<input type="hidden" name="id" value="{$item[id]}">
				{if !empty($item) && empty($item['linkurl'])}
					<div class="form-group">
						<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">访问地址</label>
						<div class="col-sm-8 col-xs-12">
							<p class="form-control-static"><a href="/app/index.php?c=site&a=site&do=detail&id={$item['id']}&i={$_W['uniacid']}" target="_blank">/app/index.php?c=site&a=site&do=detail&id={$item['id']}&i={$_W['uniacid']}</a></p>
							<div class="help-block">您可以根据此地址，添加回复规则，设置访问。</div>
						</div>
					</div>
				{/if}
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">排序</label>
					<div class="col-sm-8 col-xs-12">
						<input type="text" class="form-control" placeholder="" name="displayorder" value="{$item['displayorder']}">
						<span class="help-block">文章的显示顺序，越大则越靠前</span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">标题</label>
					<div class="col-sm-8 col-xs-12">
						<input type="text" class="form-control" placeholder="" name="title" value="{$item['title']}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">文章来源</label>
					<div class="col-sm-8 col-xs-12">
						<input type="text" class="form-control" placeholder="" name="source" value="{$item['source']}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">文章作者</label>
					<div class="col-sm-8 col-xs-12">
						<input type="text" class="form-control" id="writer" name="author" value="{$item['author']}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">缩略图</label>
					<div class="col-sm-8 col-xs-12">
						{php echo tpl_form_field_image('thumb', $item['thumb'])}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
					<div class="col-sm-9 col-xs-12">
						<label>
						封面（大图片建议尺寸：360像素 * 200像素）
						</label>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
					<div class="col-sm-9 col-xs-12">
						<label class="checkbox-inline">
							<input type="checkbox" name="incontent" value="1" {if !empty($item['incontent'])} checked="checked" {/if} /> 封面图片显示在正文中
						</label>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">简介</label>
					<div class="col-sm-8 col-xs-12">
						<textarea class="form-control" name="description" rows="5">{$item['description']}</textarea>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"></label>
					<div class="col-sm-8">
						<div class="help-block"><label class="checkbox-inline"><input type="checkbox" name="autolitpic" value="1"{if empty($item['thumb'])} checked="true"{/if}>提取内容的第一个图片为缩略图</label></div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">内容</label>
					<div class="col-sm-8 col-xs-12">
						<textarea class="form-control richtext" name="content" rows="10">{$item['content']}</textarea>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">直接链接</label>
					<div class="col-sm-8 col-xs-12">
						{php echo tpl_form_field_link('linkurl', $item['linkurl']);}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">阅读次数</label>
					<div class="col-sm-8 col-xs-12">
						<input type="text" name="click" value="{$item['click']}" class="form-control"/>
						<div class="help-block">默认为0。您可以设置一个初始值,阅读次数会在该初始值上增加。</div>
					</div>
				</div>
		</div>
	</div>
	<div class="form-group">
		<div class="col-sm-12">
			<input name="submit" type="submit" value="提交" class="btn btn-primary col-lg-1">
			<input type="hidden" name="token" value="{$_W['token']}" />
		</div>
	</div>
</form>
</div>
<script type="text/javascript">
	var category = {php echo json_encode($children)};
	require(['jquery', 'util'], function($, u){
		$(function(){
			u.editor($('.richtext')[0]);
		});
		$('#credit1').click(function(){
			$('#credit-status1').show();
		});
		$('#credit0').click(function(){
			$('#credit-status1').hide();
		});
	});
</script>
{/if}
{template 'common/footer'}
